var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardNo:'',
    cardPwd: '',
    isPassword: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  changeEyeOpen: function () {
    var isPassword = this.data.isPassword;
    if (isPassword == true) {
      isPassword = false;
    }
    else {
      isPassword = true;
    }
    this.setData({ isPassword: isPassword });
  },
  scanCard: function () {
    var that = this;
    wx.scanCode({
      success: function (res) {
        console.log(res.result);
        that.setData({
          cardNo: res.result
        });
      }
    });
  },
  goBack:function(){
    wx.navigateBack({});
  },
  cardInput:function(e){
    this.setData({
      cardNo: e.detail.value
    });
  },
  pwdInput:function(e){
    this.setData({
      cardPwd: e.detail.value
    });
  },
  useCashCardAction:function(){
    console.log(this.data.cardNo+'|'+this.data.cardPwd);
    if(this.data.cardNo == '' || this.data.cardPwd == ''){
      return;
    }
    var url = '/yuanmai_we/mcake/order/cashCard/verify';
    var params = {
      cardNo: this.data.cardNo,
      cardPwd: this.data.cardPwd
    }
    app.loadDataFromServer(url, this.useCashCardActionCallBack,params,'post',true);
  },
  useCashCardActionCallBack:function(res){
    console.log(res);
    if (res.success){
      app.globalData.tempCashCard = {
        cardNo: this.data.cardNo,
        cardPwd: this.data.cardPwd
      };
      wx.navigateBack({});
    }
  }
})